Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for wrap-nested-params and multi-valued parameters without '[]' #23

Closed

Conversation

christophermaier
Copy link

(sorry about the previous pull request... I missed a commit somehow)

I recently had to use a multiple select box on an HTML form, but didn't end the parameter name with "[]". wrap-params correctly transforms "foo=bar&foo=baz" into {"foo" ["bar" "baz"]}, but because the parameter was "foo" and not "foo[]", wrap-nested-params turned it into {"foo" "baz"}, eating all but the last value.

While this can be "fixed" by just calling the parameter "foo[]" from the beginning, it makes that a special case; you don't have to think about the brackets and whatnot when using the 'with-groups' macro in Hiccup, for instance (can't speak for other libraries like Enlive, though). In any event, wrap-nested-params was removing legitimate parameter values.

There is probably a better way to go about this; I just added another key to the middleware options map for a "multi-value-suffix" that defaults to "[]", in keeping with using the parse-nested-keys default parse function. Basically, if a multi-valued parameter is detected whose name doesn't end in the specified suffix, it gets added in the param-pairs function, making it appear "correct" to the rest of the machinery. It works, though.

Thanks,
Chris

…parameters that don't end in '[]', produced by e.g., multiple select elements.

For example, the query string "foo=bar&foo=baz".
@weavejester
Copy link
Collaborator

As you say, there is probably a better solution for this than adding an additional option. I'll look into a fix for this.

@timewarrior
Copy link

Hi
I am also facing this issue.
{"fooz" [{"baz" {"foo" "bar1"}} {"baz" {"foo" "bar2"}}]} is getting converted to {"fooz" {"baz" {"foo" "bar2"}}} losing the last value. For now I have disabled wrap-nested-params from my code. I would really appreciate if there was some fix for this.

Thanks
Anand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants